package org.example.DesignPatterns.Proxy.AOP;

import java.lang.reflect.Method;
import java.util.Arrays;

/**
 * @description:ServiceLogAspect的目的是在类ServiceA和ServiceB所有方法的执行前后加一些日志
 * @author: farprt
 * @create: 2022-08-14 16:04
 **/
@Aspect({ServiceA.class,ServiceB.class})
public class ServiceLogAspect {
    public static void before(Object obj, Method method,Object[] args){
        System.out.println("entering"+method.getDeclaringClass().getSimpleName()+"::"+method.getName()+",args:"+ Arrays.toString(args));
    }

    public static void after(Object obj, Method method,Object[] args,Object result){
        System.out.println("leaving"+method.getDeclaringClass().getSimpleName()+"::"+method.getName()+",result:"+ result);
    }

    public static void exception(Object obj, Method method,Object[] args,Throwable e){
        //System.err.println("exception when calling:"+method.getName()+","+ Arrays.toString(args));
    }
}